package com.operate.api.app.balance.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.operate.api.app.balance.dao.AppBalanceDao;
import com.operate.api.app.balance.domain.vo.AppBalanceSearchVO;
import com.operate.api.app.balance.domain.vo.AppBalanceVO;
import com.operate.api.app.balance.domain.vo.AppOrderConsumeVO;
import com.operate.api.app.balance.domain.vo.AppOrderRechargeVO;
import com.operate.api.app.balance.service.IAppBalanceService;
import com.operate.api.app.message.dao.AppMessageDao;
import com.operate.api.base.Type;
import com.operate.api.operate.dramas.dao.VideoDao;
import com.operate.api.operate.dramas.domain.po.VideoPO;
import com.operate.api.operate.order.dao.OrderConsumeDao;
import com.operate.api.operate.order.dao.OrderRechargeDao;
import com.operate.api.operate.order.domain.po.OrderConsumePO;
import com.operate.api.operate.order.domain.po.OrderRechargePO;
import com.operate.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
@Slf4j
public class AppBalanceServiceImpl implements IAppBalanceService {

    @Autowired
    private AppBalanceDao dao;
    @Autowired
    private OrderConsumeDao consumeDao;
    @Autowired
    private OrderRechargeDao rechargeDao;
    @Autowired
    private VideoDao videoDao;

    @Override
    public List<AppBalanceVO> getList(AppBalanceSearchVO searchVO) {
        searchVO.setUserId(StpUtil.getLoginId().toString());
        return dao.getList(searchVO);
    }

    @Override
    public AppOrderRechargeVO getRechargeDesc(String id) {
        OrderRechargePO orderRechargePO=rechargeDao.selectByPrimaryKey(id);
        if(orderRechargePO==null){
            throw new BusinessException(Type.FAIL.getCode(),"信息未找到！");
        }
        AppOrderRechargeVO rechargeVO=new AppOrderRechargeVO();
        BeanUtils.copyProperties(orderRechargePO, rechargeVO);
        return rechargeVO;
    }

    @Override
    public AppOrderConsumeVO getConsumeDesc(String id) {
        OrderConsumePO orderConsumePO=consumeDao.selectByPrimaryKey(id);
        if(orderConsumePO==null){
            throw new BusinessException(Type.FAIL.getCode(),"信息未找到！");
        }
        VideoPO videoPO=videoDao.selectByPrimaryKey(orderConsumePO.getVideoId());
        AppOrderConsumeVO consumeVO=new AppOrderConsumeVO();
        BeanUtils.copyProperties(orderConsumePO, consumeVO);
        consumeVO.setVideoName(videoPO.getVideoName());
        return consumeVO;
    }
}